package bean.life.xml;

import diy.listener.DiyBeforeBeanInitEvent;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 自定义的监听者，嵌入到Spring源码发布。
 * 自定义的事件见{@link DiyBeforeBeanInitEvent}
 *
 * @date 2020/5/24 22:06
 */
public class XMLListener implements ApplicationListener, InitializingBean {

	public XMLListener() {
		System.out.println("XMLListener 被实例化了。。，因为需要监听DiyBeforeBeanInitEvent事件");
	}

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		if (event instanceof ContextRefreshedEvent) {
			System.out.println("【context刷新完毕 ,listener监听器回调了】");
		}

		if (event instanceof DiyBeforeBeanInitEvent) {
			System.out.println("【自定义的事件DiyBeforeBeanInitEvent 发布】");
		}
		if (event instanceof ContextClosedEvent) {
			System.out.println("【context关闭了 ,listener监听器回调了】");
		}
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("XMLListener 的 afterPropertiesSet");
	}
}
